require 'crawler/crawler'
require 'uri'
require 'date'

module Crawler
  class FacebookCrawler < Crawler
    
    public
    
    def initialize( args={} )
      super(args)
    end
    
    def service_name
      'facebook'
    end
    
    def crawl_table
      FacebookCrawl  
    end
    
    protected
    
    def crawl(c)
      profile_uri = URI.parse(c.service.user_url_on_service)
      request_uri = "https://graph.facebook.com/#{profile_uri.query.split('=')[1]}"
      @curl.url = request_uri
      @curl.http_get
      
      if @curl.body_str.eql? "false" then
        c.status = 404
        response = false
      else
        c.status = @curl.response_code
        response = @curl.response_code == 200
      end
      
      c.body = @curl.body_str
      response
    end
    
    def has_crawl?(s)
      !s.facebook_crawl.nil?
    end
    
  end
end
